package com.lagou.edu.utils;

import com.alibaba.druid.pool.DruidPooledConnection;
import com.lagou.edu.annotation.Service;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;

@Service("connectionUtils")
public class ConnectionUtils {
    private static  ThreadLocal<Connection> connectionThreadLocal = new ThreadLocal<>();

    //获取当前的connection
    public  Connection getCurrentConnection() throws SQLException {
        Connection connection = connectionThreadLocal.get();
        if(null == connection){
            connection = DruidUtils.getInstance().getConnection();
            connectionThreadLocal.set(connection);
        }
        return connection;
    }
}
